package edu.columbia.plt.visage.tests;

import java.awt.Color;
import java.util.*;

import org.junit.*;

import edu.columbia.plt.visage.Agent;
import edu.columbia.plt.visage.Cell;
import edu.columbia.plt.visage.Matrix;
import edu.columbia.plt.visage.interfaces.ICell;


public class unit_test {

	private Map<String, Map<Integer, Agent>> agentTypeMap;
	
	private Color color;

	private Cell cell;
	
	ArrayList<Agent> agentList1;
	
	private int index;
	
	Agent new_agent;
	
	int width, height, cellSize;
	
	private Matrix matrix;
	
	@Before 
	public void setUp()
	{
		agentList1=new ArrayList<Agent>();		
		cell=new Cell();
		new_agent=new Agent();
		new_agent.setColor(Color.gray);
		new_agent.setSize(12);
		new_agent.setSpeed(10);
		agentList1.add(new_agent);
		agentTypeMap = new LinkedHashMap<String, Map<Integer, Agent>>();

	}
	
	@After
	public void tearDown()
	{
		agentList1.clear();
		
	}
	
	@Test
    public void testgetAgentsByColor() {
			
		try {
			//agentList1=(ArrayList<Agent>)cell.getAgentsByColor(Color.gray);
		    index=agentList1.size();
    	}
    	catch(Exception n) {	
    	}
    	
    	//System.out.print(index);

     	Assert.assertEquals(Color.gray, agentList1.get(index-1).getColor());
     
    }
    
	@Test
    public void testgetAgentsBySize() {
			
		try {
			  index=agentList1.size();

    	}

    	catch(Exception n) {
    		
    	}  	
    	Assert.assertEquals(12, agentList1.get(index-1).getSize());
    	 
	}
	
    @Test  
	public void testaddAgent() {
			
    	if (!agentTypeMap.containsKey(new_agent.getType())) {
			agentTypeMap.put(new_agent.getType(),
					new LinkedHashMap<Integer, Agent>());
		}
		
		Map<Integer, Agent> agentMap = agentTypeMap.get(new_agent.getType());
		agentMap.put(new_agent.getID(), new_agent);
		
		Assert.assertFalse(agentMap.isEmpty());
		
	}

    @Test
	public void testmoverandom() {
    	double tmpSpeed = new_agent.getSpeed()* Math.random();
    	double x=0,y=0;
    	x += tmpSpeed * Math.cos(Math.toRadians(360 * Math.random()));	
    	y += tmpSpeed * Math.sin(Math.toRadians(360 * Math.random()));
	
    }
	
    @Test
	public void removeAllAgents() {
		agentTypeMap.clear();
		Assert.assertTrue(agentTypeMap.isEmpty());		
	}
    
    
    @Test
    public void testproduce() {
		
    	int number=5;
		
		String type="Wolf";
    	
    	Collection<Agent> set = new HashSet<Agent>();
    	
		for (int i = 0; i < number; i++) {
			
			//Agent agent = new Agent(this);
			
			Agent agent= new Agent();
			
			agent.setType(type);
			
			set.add(agent);
			
		}
		Assert.assertTrue(set.size()==5);
		//Assert.assertTrue(set.size().);
		//Assert.assertTrue(5, );
		//return set;	
	}
    
	@Test
    public void testreproduce() {
		int number=5;
		
		Collection<Agent> set = new HashSet<Agent>();
		
		for (int i = 0; i < number; i++) {
			Agent agent = new Agent();
			set.add(agent);
		}
		//return set;
		Assert.assertTrue(set.size()==5);	
	}
    
	@Test 
	public void  testgetAgentList() {
		
		ArrayList<Agent> agentList = new ArrayList<Agent>();
		
		for (String agentType : agentTypeMap.keySet()) {
			Map<Integer, Agent> agentMap = agentTypeMap.get(agentType);
			agentList.addAll(agentMap.values());
		}
		
		Assert.assertTrue(agentList.isEmpty());
		//return agentList;
	}
	
	
	
	
	
	
	}
	